#include "card.h"
#include "def.h"
#include<QPainter>
#include<QtGui>
//создание пустой карты(рубашки)
Card::Card()
{
	face = false;
}
//Создание карты из её порядкового номера
Card::Card(int num, bool shirt)
{
	face_num = num;
	if (shirt)
	{
		//карты игрока видно на столе
//		setFlags(QGraphicsItem::ItemIsMovable);
		switch (num)
		{
			case SIX_CROSSES:
			{
				face_img = QImage("card/33.png");
				break;
			}
			case SIX_PINOCHELE:
			{
				face_img = QImage("card/34.png");
				break;
			}
			case SIX_WORM:
			{
				face_img = QImage("card/35.png");
				break;
			}
			case SIX_BUBI:
			{
				face_img = QImage("card/36.png");
				break;
			}
			case SEVEN_CROSSES:
			{
				face_img = QImage("card/29.png");
				break;
			}
			case SEVEN_PINOCHELE:
			{
				face_img = QImage("card/30.png");
				break;
			}
			case SEVEN_WORM:
			{
				face_img = QImage("card/31.png");
				break;
			}
			case SEVEN_BUBI:
			{
				face_img = QImage("card/32.png");
				break;
			}
			case EIGHT_CROSSES:
			{
				face_img = QImage("card/25.png");
				break;
			}
			case EIGHT_PINOCHELE:
			{
				face_img = QImage("card/26.png");
				break;
			}
			case EIGHT_WORM:
			{
				face_img = QImage("card/27.png");
				break;
			}
			case EIGHT_BUBI:
			{
				face_img = QImage("card/28.png");
				break;
			}
			case NINE_CROSSES:
			{
				face_img = QImage("card/21.png");
				break;
			}
			case NINE_PINOCHELE:
			{
				face_img = QImage("card/22.png");
				break;
			}
			case NINE_WORM:
			{
				face_img = QImage("card/23.png");
				break;
			}
			case NINE_BUBI:
			{
				face_img = QImage("card/24.png");
				break;
			}
			case TEN_CROSSES:
			{
				face_img = QImage("card/17.png");
				break;
			}
			case TEN_PINOCHELE:
			{
				face_img = QImage("card/18.png");
				break;
			}
			case TEN_WORM:
			{
				face_img = QImage("card/19.png");
				break;
			}
			case TEN_BUBI:
			{
				face_img = QImage("card/20.png");
				break;
			}
			case JACK_CROSSES:
			{
				face_img = QImage("card/13.png");
				break;
			}
			case JACK_PINOCHELE:
			{
				face_img = QImage("card/14.png");
				break;
			}
			case JACK_WORM:
			{
				face_img = QImage("card/15.png");
				break;
			}
			case JACK_BUBI:
			{
				face_img = QImage("card/16.png");
				break;
			}
			case QUEEN_CROSSES:
			{
				face_img = QImage("card/9.png");
				break;
			}
			case QUEEN_PINOCHELE:
			{
				face_img = QImage("card/10.png");
				break;
			}
			case QUEEN_WORM:
			{
				face_img = QImage("card/11.png");
				break;
			}
			case QUEEN_BUBI:
			{
				face_img = QImage("card/12.png");
				break;
			}
			case KING_CROSSES:
			{
				face_img = QImage("card/5.png");
				break;
			}
			case KING_PINOCHELE:
			{
				face_img = QImage("card/6.png");
				break;
			}
			case KING_WORM:
			{
				face_img = QImage("card/7.png");
				break;
			}
			case KING_BUBI:
			{
				face_img = QImage("card/8.png");
				break;
			}
			case ACE_CROSSES:
			{
				face_img = QImage("card/1.png");
				break;
			}
			case ACE_PINOCHELE:
			{
				face_img = QImage("card/2.png");
				break;
			}
			case ACE_WORM:
			{
				face_img = QImage("card/3.png");
				break;
			}
			case ACE_BUBI:
			{
				face_img = QImage("card/4.png");
				break;
			}
		}
		face = true;
	}
	else
	{
		//карты компьютера не видно
		face_img = QImage("card/shirt.png");
		face = false;
	}
	//определение цености карт
	if ((face_num>=SIX_BUBI) && (face_num<=NINE_CROSSES))
	{
		value = 0;
	}
	else if ((face_num>=TEN_BUBI) && (face_num<=TEN_CROSSES))
	{
		value = 10;
	}
	else if ((face_num>=JACK_BUBI) && (face_num<=JACK_CROSSES))
	{
		value = 2;
	}
	else if ((face_num>=QUEEN_BUBI) && (face_num<=QUEEN_CROSSES))
	{
		value = 3;
	}
	else if ((face_num>=KING_BUBI) && (face_num<=KING_CROSSES))
	{
		value = 4;
	}
	else if ((face_num>=ACE_BUBI) && (face_num<=ACE_CROSSES))
	{
		value = 11;
	}
	//определение масти и значения карты(её картинка)
	suit = face_num%4;
	face_value = face_num-suit;
	
}
QRectF Card::boundingRect() const
{
	return QRectF(0, 0, 72.0, 96.0);
}
//Отрисовка выбранного в конструкторе лица карты
void Card::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
{
	painter->save();
	painter->drawImage(0, 0, face_img);
	painter->restore();
}

void Card::setShirt()
{
//	setFlags(QGraphicsItem::ItemIsMovable);
	switch (face_num)
	{
		case SIX_CROSSES:
		{
			face_img = QImage("card/33.png");
			break;
		}
		case SIX_PINOCHELE:
		{
			face_img = QImage("card/34.png");
			break;
		}
		case SIX_WORM:
		{
			face_img = QImage("card/35.png");
			break;
		}
		case SIX_BUBI:
		{
			face_img = QImage("card/36.png");
			break;
		}
		case SEVEN_CROSSES:
		{
			face_img = QImage("card/29.png");
			break;
		}
		case SEVEN_PINOCHELE:
		{
			face_img = QImage("card/30.png");
			break;
		}
		case SEVEN_WORM:
		{
			face_img = QImage("card/31.png");
			break;
		}
		case SEVEN_BUBI:
		{
			face_img = QImage("card/32.png");
			break;
		}
		case EIGHT_CROSSES:
		{
			face_img = QImage("card/25.png");
			break;
		}
		case EIGHT_PINOCHELE:
		{
			face_img = QImage("card/26.png");
			break;
		}
		case EIGHT_WORM:
		{
			face_img = QImage("card/27.png");
			break;
		}
		case EIGHT_BUBI:
		{
			face_img = QImage("card/28.png");
			break;
		}
		case NINE_CROSSES:
		{
			face_img = QImage("card/21.png");
			break;
		}
		case NINE_PINOCHELE:
		{
			face_img = QImage("card/22.png");
			break;
		}
		case NINE_WORM:
		{
			face_img = QImage("card/23.png");
			break;
		}
		case NINE_BUBI:
		{
			face_img = QImage("card/24.png");
			break;
		}
		case TEN_CROSSES:
		{
			face_img = QImage("card/17.png");
			break;
		}
		case TEN_PINOCHELE:
		{
			face_img = QImage("card/18.png");
			break;
		}
		case TEN_WORM:
		{
			face_img = QImage("card/19.png");
			break;
		}
		case TEN_BUBI:
		{
			face_img = QImage("card/20.png");
			break;
		}
		case JACK_CROSSES:
		{
			face_img = QImage("card/13.png");
			break;
		}
		case JACK_PINOCHELE:
		{
			face_img = QImage("card/14.png");
			break;
		}
		case JACK_WORM:
		{
			face_img = QImage("card/15.png");
			break;
		}
		case JACK_BUBI:
		{
			face_img = QImage("card/16.png");
			break;
		}
		case QUEEN_CROSSES:
		{
			face_img = QImage("card/9.png");
			break;
		}
		case QUEEN_PINOCHELE:
		{
			face_img = QImage("card/10.png");
			break;
		}
		case QUEEN_WORM:
		{
			face_img = QImage("card/11.png");
			break;
		}
		case QUEEN_BUBI:
		{
			face_img = QImage("card/12.png");
			break;
		}
		case KING_CROSSES:
		{
			face_img = QImage("card/5.png");
			break;
		}
		case KING_PINOCHELE:
		{
			face_img = QImage("card/6.png");
			break;
		}
		case KING_WORM:
		{
			face_img = QImage("card/7.png");
			break;
		}
		case KING_BUBI:
		{
			face_img = QImage("card/8.png");
			break;
		}
		case ACE_CROSSES:
		{
			face_img = QImage("card/1.png");
			break;
		}
		case ACE_PINOCHELE:
		{
			face_img = QImage("card/2.png");
			break;
		}
		case ACE_WORM:
		{
			face_img = QImage("card/3.png");
			break;
		}
		case ACE_BUBI:
		{
			face_img = QImage("card/4.png");
			break;
		}
	}
	face = true;
}
